package saei.persistencia;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import saei.bean.*;
import saei.bean.parametros.Ciudad;
import saei.bean.parametros.MarcaEquipo;
import saei.bean.parametros.MarcaSoftware;
import saei.bean.parametros.ModeloCpu;
import saei.bean.parametros.ModeloImpresora;
import saei.bean.parametros.ModeloMonitor;
import saei.bean.parametros.ModeloUps;
import saei.bean.parametros.ModoImpresion;
import saei.bean.parametros.Parametro;
import saei.bean.parametros.Procesador;
import saei.bean.parametros.Proveedor;
import saei.bean.parametros.Provincia;
import saei.bean.parametros.Sector;
import saei.bean.parametros.TipoConectividad;
import saei.bean.parametros.TipoPantalla;

public class HibernateUtil
{
    private static final SessionFactory sessionFactory;
    static
    {
        try
        {
            AnnotationConfiguration config = new AnnotationConfiguration();

            config.addAnnotatedClass(Asignacion.class);
            config.addAnnotatedClass(CodigoPostal.class);
            config.addAnnotatedClass(Cpu.class);
            config.addAnnotatedClass(Equipo.class);
            config.addAnnotatedClass(EquipoAsignado.class);
            config.addAnnotatedClass(Estado.class);
            config.addAnnotatedClass(Impresora.class);
            config.addAnnotatedClass(Licencia.class);
            config.addAnnotatedClass(Monitor.class);
            
            config.addAnnotatedClass(SolicitudCompra.class);
            config.addAnnotatedClass(Remito.class);
            config.addAnnotatedClass(Representacion.class);
            config.addAnnotatedClass(Rol.class);
            config.addAnnotatedClass(Software.class);
            config.addAnnotatedClass(Ups.class);
            config.addAnnotatedClass(Usuario.class);
                 
            config.addAnnotatedClass(Parametro.class);
            config.addAnnotatedClass(MarcaEquipo.class);
            config.addAnnotatedClass(ModeloCpu.class);
            config.addAnnotatedClass(ModeloImpresora.class);
            config.addAnnotatedClass(ModeloUps.class);
            config.addAnnotatedClass(ModeloMonitor.class);
            config.addAnnotatedClass(Procesador.class);
            config.addAnnotatedClass(TipoPantalla.class);
            config.addAnnotatedClass(MarcaSoftware.class);
            config.addAnnotatedClass(ModoImpresion.class);
            config.addAnnotatedClass(TipoConectividad.class);
            config.addAnnotatedClass(Sector.class);
            config.addAnnotatedClass(Provincia.class);
            config.addAnnotatedClass(Ciudad.class);
            config.addAnnotatedClass(Proveedor.class);
            
            config.addAnnotatedClass(PlanRotacion.class);
            config.addAnnotatedClass(ItemPlanRotacion.class);
            
            sessionFactory = config.buildSessionFactory();
        }
        catch (Throwable ex)
        {
            System.err.println("Initial SessionFactory creation failed. " + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    public static Session getSession()throws HibernateException {
    	return sessionFactory.openSession();
    }
 
    public static SessionFactory getSessionFactory()
    {
        return sessionFactory;
    }
}
